package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
@RequiredArgsConstructor
@Slf4j
public class WmChannelController {

    private final WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult findList() {
        log.info("查询所有的频道列表");
        return wmChannelService.findList();
    }

    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel) {
        log.info("保存频道信息：{}", wmChannel);
        return wmChannelService.saveChannel(wmChannel);
    }

    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        log.info("根据名称分页查询频道信息：{}", channelDto);
        return wmChannelService.findByNameAndPage(channelDto);
    }
    @GetMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") Integer id) {
        log.info("根据id删除频道信息：{}", id);
        return wmChannelService.delChannel(id);
    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel) {
        log.info("修改频道信息：{}", wmChannel);
        return wmChannelService.updateChannel(wmChannel);
    }
}
